<?php
class classifiedApi extends core
{
	public function releaseAction($arg)
	{
		$website	= base::init('website')->getRow(array('wid'=>$arg['wid']));
		$attr		= base::init('website')->getConfig($website['domain']);
		$template	= $this->template();
		$islogin	= false;

		$template->template_dir = ROOT . $attr['tempdir'] ;

		if (isset($cookie['username']))
		{
			$array		= array('username'=>($cookie['username']),'ip'=>get_real_ip(),'useragent'=>$_SERVER['HTTP_USER_AGENT'],'domain'=>$website['domain']);
			$islogin	= @base::init('member')->isLogin($cookie['user'], $array);
		}
		
		/*if (!$islogin)
		{
			$columns	= base::init('column')->getAll(array('wid'=>$arg['wid']));
			$columns	= base::init('column')->listcls($columns,0);
			$template->display(ROOT . $attr['tempdir'] . 'login.php');
			die;
		}
		*/
		if (isPost())
		{
			$arg['passdate'] = strtotime($arg['passdate']);
			$arg['posttime'] = time();
			$arg['flag']     = isset($arg['flag']) ? join(',',$arg['flag']) : '';
			base::init('classified')->insert($arg);
			$this->refresh('添加成功', $arg['referrer']);
		}
		else 
		{
			
			$columns	= base::init('column')->getAll(array('wid'=>$arg['wid']));
			$columns	= base::init('column')->listcls($columns,0);
			
			$infotype	= base::init('infotype')->getAll();
			
			
			$template->assign('columns', $columns);
			$template->assign('attr', $attr);
			$template->assign('website', $website);
			$template->assign('ip', get_real_ip());
			$template->assign('infotype', $infotype);
			$template->display('classified_release.php');
		}
	}

	public function addAction($arg)
	{
		if (isPost())
		{
			$arg['passdate'] = strtotime($arg['passdate']);
			$arg['posttime'] = time();
			$arg['flag']     = isset($arg['flag']) ? join(',',$arg['flag']) : '';
			base::init('classified')->insert($arg);
			$this->refresh('添加成功', $arg['referrer']);
		}
		else 
		{
			$template	= $this->template();
			$columns	= base::init('column')->getAll(array('wid'=>$arg['wid']));
			$columns	= base::init('column')->listcls($columns, 0);
			$infotype	= base::init('infotype')->getAll();
			
			$template->assign('columns', $columns);
			$template->assign('ip', get_real_ip());
			$template->assign('infotype', $infotype);
			$template->display('classified_add.php');
		}
	}
}